home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freaks Macintosh Archive
/
Freaks Macintosh Archive.bin
/
Freaks Macintosh Archives
/
Crypto⁄Encryption
/
TV (CANAL+) decoder.sit
/
Premium (CANAL+) decoder
/
Prefs.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-11-05
|
9KB
|
394 lines
/*
Premium v0.1
© InMarv from Cologne : greetings to everyone..
Modified by SkRf from Tahiti (5/11/98)
*/
#include <Errors.h>
#include <Types.h>
#include <Memory.h>
#include <Quickdraw.h>
#include <Fonts.h>
#include <Events.h>
#include <Menus.h>
#include <Windows.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <OSUtils.h>
#include <ToolUtils.h>
#include <SegLoad.h>
#include <Files.h>
#include <stdio.h>
#include <Controls.h>
#include <NameRegistry.h>
#include <math.h>
#include <QDOffscreen.h>
#include <Movies.h>
#include <QuickTimeComponents.h>
#include "nagra.h"
void Premium();
/* Prototypes */
void Initialize(void);
void Handle_Menu_Choice( long menu_choice);
MenuHandle Applemenu, Filemenu;
Boolean All_Done = FALSE;
DialogPtr myDialog, AboutDiag;
short theItem, thePart;
EventRecord TheEvent;
WindowPtr theWindow;
Rect itemrect;
Handle item;
short itemtype;
short oldvalue,i, chr;
short gFullPal = 0;
short gSVHS = 1;
short gSTD = 1;
short g32bit = 0;
int main(void)
{
Handle myMenu;
long menu_choice;
SysEnvRec theWorld;
int dummy;
OSErr error;
GrafPtr oldPort;
Initialize();
myDialog = GetNewDialog( 128, 0L, (WindowPtr)-1L);
if (myDialog == 0L) return;
myMenu = GetNewMBar(128);
SetMenuBar(myMenu);
DisposeHandle(myMenu);
Applemenu = GetMenuHandle(128);
AppendResMenu( Applemenu, 'DRVR');
DrawMenuBar();
ShowWindow(myDialog);
GetPort(&oldPort); /* save the environment */
SetPort(myDialog); /* enable drawing on the dialog */
GetDialogItem(myDialog,1,&itemtype,&item, &itemrect); /* get the 'OK' Button rect */
/* Write the default button */
PenSize(3,3);
InsetRect(&itemrect, -4, -4);
FrameRoundRect(&itemrect, 16, 16);
PenSize(1,1);
SetPort(oldPort); /* restores the old port */
while (All_Done == FALSE)
{
WaitNextEvent( everyEvent, &TheEvent, 0L, 0L);
if (IsDialogEvent (&TheEvent))
{
if ( (TheEvent.what == keyDown )
&&((TheEvent.modifiers & cmdKey)!=0)
)
{
switch ( TheEvent.message & charCodeMask)
{
case 'q':
case 'w':
All_Done = TRUE;
break;
}
}
if ( DialogSelect( &TheEvent, &myDialog, &theItem))
{
switch (theItem)
{
case 5: /* full pal */
GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
oldvalue = GetControlValue( (ControlHandle)item);
SetControlValue((ControlHandle)item,(oldvalue+1)&1);
gFullPal = (oldvalue+1)&1;
SetDialogItem(myDialog,theItem,itemtype,item,&itemrect);
break;
case 6: /* 32 bit digitizing */
GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
oldvalue = GetControlValue( (ControlHandle)item);
g32bit = (oldvalue+1)&1;
SetControlValue((ControlHandle)item,(oldvalue+1)&1);
SetDialogItem(myDialog,theItem,itemtype,item,&itemrect);
break;
case 7: /* asnyc digitizing */
GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
oldvalue = GetControlValue( (ControlHandle)item);
SetControlValue((ControlHandle)item,(oldvalue+1)&1);
SetDialogItem(myDialog,theItem,itemtype,item,&itemrect);
break;
case 1: /* start */
All_Done = TRUE;
Premium();
break;
case 3: /* SVHS - FBAS */
GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
gSVHS = GetControlValue( (ControlHandle)item);
break;
case 9: /* SVHS - FBAS */
GetDialogItem(myDialog,theItem,&itemtype,&item, &itemrect);
gSTD = GetControlValue( (ControlHandle)item);
break;
}
}
} else {
switch (TheEvent.what)
{
/* case nullEvent:
DoIdle( &TheEvent );
break;
*/ case keyDown:
All_Done = TRUE;
chr = TheEvent.message & charCodeMask;
if ((TheEvent.modifiers & cmdKey)!=0)
{
if (TheEvent.what != autoKey)
{
menu_choice = MenuKey (chr);
Handle_Menu_Choice(menu_choice);
}
}
break;
case mouseDown:
thePart = FindWindow(TheEvent.where, &theWindow);
switch (thePart)
{
case inMenuBar:
menu_choice = MenuSelect(TheEvent.where);
Handle_Menu_Choice(menu_choice);
break;
case inSysWindow:
SystemClick( &TheEvent, theWindow);
break;
case inDrag:
DragWindow(theWindow, TheEvent.where, &qd.screenBits.bounds);
break;
case inGoAway:
if (TrackGoAway (theWindow, TheEvent.where))
All_Done = TRUE;
break;
case inContent:
if (theWindow != FrontWindow()) SelectWindow(theWindow);
break;
}
break;
case updateEvt:
break;
}
}
}
CloseWindow(myDialog);
}
/*
// Initialize everything for the program, make sure we can run
*/
void Initialize(void)
{
WindowPtr mainPtr;
OSErr error;
SysEnvRec theWorld;
/*
// Test the computer to be sure we can do color.
// If not we would crash, which would be bad.
// If we can’t run, just beep and exit.
*/
error = SysEnvirons(1, &theWorld);
if (theWorld.hasColorQD == false) {
SysBeep(50);
ExitToShell(); /* If no color QD, we must leave. */
}
/* Initialize all the needed managers. */
InitGraf(&qd.thePort);
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs(nil);
InitCursor();
}
void Handle_Menu_Choice( long menu_choice)
{
int the_menu, the_menu_item;
Str255 desk_acc_name;
int desk_ac_no;
if (menu_choice != 0)
{
the_menu = HiWord(menu_choice);
the_menu_item = LoWord(menu_choice);
switch(the_menu)
{
case 128:
if (the_menu_item == 1)
{
} else {
GetMenuItemText( Applemenu, the_menu_item, desk_acc_name);
desk_ac_no = OpenDeskAcc( desk_acc_name);
}
break;
case 129:
All_Done = true;
break;
}
HiliteMenu(0);
}
}
void Premium()
{
long err;
AliasHandle alias;
short i;
/* vdig thingies */
Component vThing;
ComponentDescription vThingDesc;
ComponentInstance vThingInst;
Rect maxSrcRect, activeRect, globalRect;
PixMapHandle videoPixMapH;
int sx, sy, sbpp, image_size;
unsigned char *buffer=NULL, *addr=NULL;
unsigned char *base;
int width, flags, posx, posy;
int pal, grab, allkeys, decoder;
unsigned char *lines[YSIZE];
/* offscreen */
GrafPtr origPort;
GDHandle origDev;
QDErr myErr;
GWorldPtr myOffGWorld;
PixMapHandle offPixMapHandle ;
Boolean good;
Rect sourceRect, destRect;
GDevice **MainDevice;
pal = 1; /* pal decoding */
allkeys = 1; /* preselect keys */
decoder = 1;
MainDevice = GetMainDevice();
SetWTitle(myDialog, "\pComputing Tables...");
vThingDesc.componentType = 'vdig';
vThingDesc.componentSubType = 0;
vThingDesc.componentManufacturer = 0;
vThingDesc.componentFlags = 0;
vThingDesc.componentFlagsMask = 0;
vThing = FindNextComponent((Component) 0, &vThingDesc);
vThingInst = OpenComponent(vThing);
if (vThingInst == 0) goto bail;
if (gSVHS == 1)
VDSetInput(vThingInst, sVideoIn);
else
VDSetInput(vThingInst, compositeIn);
VDSetInputStandard(vThingInst, gSTD);
VDGetMaxSrcRect(vThingInst, gSTD, &maxSrcRect);
VDGetActiveSrcRect(vThingInst, gSTD, &activeRect);
VDSetDigitizerRect(vThingInst, &activeRect);
videoPixMapH = (PixMapHandle) NewHandle(sizeof(PixMap));
**videoPixMapH = **((**MainDevice).gdPMap);
VDSetPlayThruOnOff(vThingInst, vdPlayThruOff);
sourceRect.top = 0;
sourceRect.left = 0;
sourceRect.right = 768/2;
sourceRect.bottom = 576/2;
destRect = sourceRect;
GetGWorld((struct CGrafPort **)(&origPort), &origDev);
if (g32bit)
myErr = NewGWorld(&myOffGWorld, 32, /* create offscreen graphics world, */
&sourceRect,
0, 0, 0);
else
myErr = NewGWorld(&myOffGWorld, 16, /* create offscreen graphics world, */
&sourceRect,
0, 0, 0);
if (myErr == noErr)
{
SetGWorld(myOffGWorld, 0);
offPixMapHandle = GetGWorldPixMap(myOffGWorld);
if (offPixMapHandle == 0) goto bail;
LockPixels(offPixMapHandle);
VDSetPlayThruDestination(vThingInst, offPixMapHandle, &sourceRect, nil, nil);
SetGWorld((struct CGrafPort *)origPort, origDev);
} else goto bail;
init_decode_nagra();
sx = 384; sy = 576/2; sbpp = 2;
width = ((**videoPixMapH).rowBytes);
width &= 0xfff;
width /= 2;
addr = (unsigned char *)(**offPixMapHandle).baseAddr;
base = (unsigned char *)(**videoPixMapH).baseAddr;
posx = 0;
posy = 0;
allkeys = 1;
pal = 0;
#define TOPSHIFT 32
if (g32bit)
{
for (i = 0; i < TOPSHIFT; i++) lines[i] = addr+(sx+4)*(YSIZE-TOPSHIFT + i)*4;
for (i = 0; i < YSIZE-TOPSHIFT; i++) lines[i + TOPSHIFT] = addr+(sx+4)*i*4;
} else {
for (i = 0; i < TOPSHIFT; i++) lines[i] = addr+(sx+8)*(YSIZE-TOPSHIFT + i)*2;
for (i = 0; i < YSIZE-TOPSHIFT; i++) lines[i + TOPSHIFT] = addr+(sx+8)*i*2;
}
SetWTitle(myDialog, "\pDecoding... click mouse to stop.");
while (!Button()) {
err = VDGrabOneFrame(vThingInst);
if (err != noErr) goto bail;
decode_frame(base + (width * posy + posx) * 2,width,lines,
sx,sy,1,gFullPal,g32bit);
}
CloseComponent(vThingInst);
UnlockPixels(offPixMapHandle);
DisposeGWorld(myOffGWorld);
bail:
return;
}